import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'



//公共路由
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'Dashboard', icon: 'dashboard', affix: true }/**表示不可关闭标签 affix: true  */
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }

]


//动态路由
export const asyncRoutes = [
  {
    path: '/system',
    component: Layout,
  
    alwaysShow: true,
    name: '系统管理',
    meta: { title: '系统管理', icon: 'el-icon-s-tools', roles: ['admin', 'test'] },
    children: [
      {
        path: 'user',
        name: '用户列表',
        component: () => import('@/views/users/index.vue'),
        meta: { title: '用户列表', icon: 'table', roles: ['admin', 'test'] }
      },
      {
        path: 'menu',
        name: '菜单管理',
        component: () => import('@/views/menu/index.vue'),
        meta: { title: '菜单管理', icon: 'table', roles: ['admin', 'test'] ,noCache:false}
      },
      {
        path: 'role',
        name: '角色列表',
        component: () => import('@/views/roles/index.vue'),
        meta: { title: '角色列表', icon: 'table', roles: ['admin'] }
      }
     ]
  },
  {
    path: '/network',
    component: Layout,
    
    alwaysShow: true,
    name: '网络中心',
    meta: { title: '网络中心', icon: 'el-icon-s-tools', roles: ['admin', 'test'] },
    children: [
      {
        path: 'ip',
        name: 'IP管理',
        component: () => import('@/views/net/index.vue'),
        meta: { title: 'IP管理', icon: 'table', roles: ['admin', 'test'] }
      },
      {
        path: 'dev',
        name: '设备管理',
        component: () => import('@/views/dev/index.vue'),
        meta: { title: '设备管理', icon: 'table', roles: ['admin', 'test'] ,noCache:false}
      }
     ]
  },
  { path: '*', redirect: '/404', hidden: true }
]



const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})


const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router